All Questions
119 questions
2votes
1answer
277views
Joining 'fish shell' arguments into a single string with spaces
Sorry, this question is already answered for 'bash' here: Joining bash arguments into single string with spaces. in Fish, using "'$*'" leads to this error: $* is not supported. In fish, ...
-1votes
2answers
4kviews
How does the `tr` command work?
I was playing around with tr and got some unexpected results. What is happening in these situations? I don't understand what is happening under the hood, or perhaps I'm not using this command ...
1vote
1answer
267views
How to convert all newlines to "\n" in POSIX sh strings
I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "\n". How can I do this in ...
-4votes
2answers
431views
Is it possible for any shell to interpret a string with decimal point as a number (int, float)?
This idea came to me with recent updates to Visual Studio Code, in which I usually shellcheck my code automatically as well. This is what I see, so you can get the idea: This question is very simple ...
4votes
1answer
5kviews
Convert comma separated string into json array
I have the following string in bash "3.8,3.9,3.10" Is there a way using shell to convert it into a json array, i.e. ["3.8", "3.9", "3.10"]
0votes
0answers
17views
How to returns the correct character after manipulating the output of ps ax | grep [duplicate]
I would like to have some help writing a script (which should works on freebsd where I have sh as default) that should grab a precise character when I do a "ps ax | grep" command from the ...
6votes
1answer
14kviews
Grep a list of strings [closed]
I have a multiple strings that I want to find them in a list of files that are in a same folder. So, I want to put all the strings in a sort of list and then apply the command: grep -l string *,so I ...
2votes
4answers
628views
sed command failing in script with arguments
I am trying to perform a two step string editing: Match for the string "payload". If found, then add some "#if #endif" code as shown in output file. Then copy the line containing &...
-1votes
2answers
259views
How to replace duplicate occurrences of a variable in a string? [closed]
I have a block of code that looks like this: DIV='_' STRING=’1__2__3__4__5' echo $STRING The result is: 1__2__3__4__5 I would like the result to look like this: 1_2_3_4_5 Since this is a snippet ...
17votes
1answer
26kviews
How to split a string by ':' character in bash/zsh?
I am searching for a way to split a string (variable) by : character, in a compatible way between bash and zsh. From different sources, I found the following command: str="part1=part2=part3" ...
0votes
1answer
80views
convert directory names with german 'now' date to YYYY-MM-DD
I exported pictures from mac's iPhoto. The directories are named with the date in local naming ("Day. MONTH YYYY"): 8. Mai 2013/ 13. Juli 2013/ 31. Oktober 2014/ and some of them with GPS ...
4votes
1answer
664views
zsh: Read from stdin until a string delimiter
I want to read from stdin until a string delimiter MARKER=$'\0'"BRISH_MARKER" is encountered. I tried: ❯ unset br ; print -rn -- hi${MARKER}world | { IFS= read -d "$MARKER" -r ...
0votes
2answers
634views
How to espace sequence of characters in sed?
I am new to regex and running into some frustrations. I am trying to work with strings that express directories and am having the issue reproducible by running: echo "a" | sed "s/a/home/...
0votes
1answer
4kviews
How to target and shorten a long string in bash with "..."
I'm doing some web development and I am printing out some object data in the console. I want to target one property/field denoted in output as dataURI: DFASDFKAJELKJDFSADFMLAKFJLSKDJFAJSDFL which is a ...
1vote
1answer
1kviews
How to check that a variable has new lines characters only
How do I check the variable $last_cmd has new lines only and nothing else in Zsh? Ideally done via substitution, as this is part of a prompt script, so needs to be really fast. The following gives ...